package logic

import (
	"context"
	"taobao-merchandise/models/mysql"

	"taobao-merchandise/userrpc/internal/svc"
	"taobao-merchandise/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type FileAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewFileAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FileAddLogic {
	return &FileAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 文件添加
func (l *FileAddLogic) FileAdd(in *userrpc.FileAddRequest) (*userrpc.FileAddResponse, error) {
	// todo: add your logic here and delete this line

	file := &mysql.File{
		FileUrl:  in.FileUrl,
		FileSize: in.FileSize,
		FileType: in.FileType,
	}
	err := file.FileAdd(mysql.DB)
	if err != nil {
		return nil, err
	}

	return &userrpc.FileAddResponse{
		FileId: int64(file.ID),
	}, nil
}
